package com.mikey.add;

import java.util.concurrent.CountDownLatch;

/**
 * @author :Mikey
 * @description :
 * @create :2022-09-21 11:15:00
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        //总数是6,必须要执行任务的时候，然后再使用
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 0; i < 6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"go out");
                countDownLatch.countDown();//数量减一
            },String.valueOf(i)).start();
        }
        countDownLatch.await();//等待计数器归零再向下执行，
        System.out.println("close door");
    }
}
